package bma.common.thrift;

import org.apache.thrift.TException;
import org.apache.thrift.protocol.TMessage;
import org.apache.thrift.protocol.TProtocol;

public class TProtocolCacheMessage extends TProtocolWrap {

	private transient TMessage lastMessage;

	public TProtocolCacheMessage(TProtocol protocol) {
		super(protocol);
	}

	public TMessage getLastMessage() {
		return lastMessage;
	}

	public void setLastMessage(TMessage lastMessage) {
		this.lastMessage = lastMessage;
	}

	@Override
	public TMessage readMessageBegin() throws TException {
		if (this.lastMessage == null) {
			this.lastMessage = super.readMessageBegin();
		}
		return this.lastMessage;
	}
	
	public static TProtocolCacheMessage wrapIn(TProtocol in) {
		if (in instanceof TProtocolCacheMessage) {
			return (TProtocolCacheMessage) in;
		}
		return new TProtocolCacheMessage(in);
	}
}
